package tests.fakes;

import java.util.ArrayList;
import java.util.List;

import jeconbond.automata.INode;
import jeconbond.automata.IOutcome;
import jeconbond.automata.Node;
import jeconbond.automata.Outcome;
import jeconbond.automata.behaviour.ListPlanWalker;
import jeconbond.economic.agent.AutomataAgent;
import jeconbond.economic.agent.IEconomicAgent;
import jeconbond.economic.natural.strategy.NaturalMerchant;
import jeconbond.economic.resources.IResourceType;
import jeconbond.economic.resources.ResourceBasket;
import jeconbond.economic.resources.ResourceStorrage;
import jeconbond.economic.systems.natural.NaturalResourceRedestributionSystem;

public class ResourceConverter {
	public static IEconomicAgent GeterateConverter(
			NaturalResourceRedestributionSystem nrrs, 
			IResourceType from,
			IResourceType to
	) {
		ResourceStorrage irs = new ResourceStorrage();
		ResourceStorrage ors = new ResourceStorrage();
		
		INode prev = new Node("Prev: " + from.getName() + " -> " + to.getName());
		INode post = new Node("Post: " + from.getName() + " -> " + to.getName());;
		

		IOutcome out = new Outcome(post, new ResourceBasket(from, 1.0));
		out.setProducedResources(new ResourceBasket(to, 1.0));
		prev.getOutcomes().add(out);
		post.getOutcomes().add(
				new Outcome(prev)
		);
		
		List<IOutcome> plan = new ArrayList<IOutcome>();
		plan.add(prev.getOutcomes().get(0));
		plan.add(post.getOutcomes().get(0));
		ListPlanWalker listPlanWalker = new ListPlanWalker(plan, irs, ors);
		
		NaturalMerchant merchant = new NaturalMerchant(irs, ors, listPlanWalker, nrrs);
		
		AutomataAgent agent = new AutomataAgent(prev);
		agent.setMerchant(merchant);
		agent.setWalkStrategy(listPlanWalker);
		return agent;
	}
}
